<template>
  <div>
    <TopFilter :list="partSalesInfoList" :cols="3" :labelWidth="130" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="partTable"
      :columns="partSalesColumns"
      :isSelectColumn="false"
      :datakey="'rows'"
      :dataSource="listResult"
      :onColumnsChange="columns => this.partSalesColumns = columns"
    >
      <template slot="controls">
        <el-button size="small" type="primary">导出</el-button>
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'partSalesInfo',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      partSalesInfoList: this.createPartInfoFilterList(),
      // fetchApi:'',
      // fetchParams: { xhrAbort: false },
      listResult:[],
      partSalesColumns: this.createPartColumns()
    };
  },

 methods: {
    createPartInfoFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          itemList: []
        },
        {
          type: 'RANGE_DATE',
          label: '发料日期',
          fieldName: 'STORAGE_POSITION',
          valueFormat: 'StartDate|EndDate'
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME'
        },
        {
          type: 'SELECT',
          label: '工单状态',
          fieldName: 'roStatus',
          itemList: []
        },
        {
          type: 'RANGE_DATE',
          label: '结算日期',
          fieldName: 'Begin|End'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME',
        },
        {
          type: 'SELECT',
          label: '客户类别',
          fieldName: 'customerType',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '关单日期',
          fieldName: 'closeBegin|closeEnd',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customer'
        },
        {
          type: 'SELECT',
          label: '九大类',
          fieldName: 'partMainType',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '配件车型组',
          fieldName: 'PART_MODEL_GROUP_CODE_SET',
          itemList: []
        },
         {
          type: 'INPUT',
          label: '备注',
          fieldName: 'REMARK'
        },
        {
          type: 'CHECKBOX',
          label: '已出库未结清',
          fieldName: 'isCheck1',
          itemList: []
        },
        {
          type: 'CHECKBOX',
          label: '已结清',
          fieldName: 'isCheck2',
          itemList: []
        },
        {
          type: 'CHECKBOX',
          label: '同一仓库统一配件合并',
          fieldName: 'isCheck4',
          itemList: []
        },
        {
          type: 'CHECKBOX',
          label: '已出库未结算',
          fieldName: 'isCheck3',
          itemList: []
        }

      ];
    },
    createPartColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true
        },
        {
          title: '配件销售单号',
          dataIndex: 'SALES_PART_NO',
          sorter: true
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '配件车型组集',
          dataIndex: 'PART_MODEL_GROUP_CODE_SET',
          sorter: true
        },
        {
          title: '配件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true
        },
        {
          title: '配件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true
        },
        {
          title: '配件销售金额',
          dataIndex: 'SALES_AMOUNT',
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'SALES_DISCOUNT',
          sorter: true
        },
        {
          title: '配件收费金额',
          dataIndex: 'PART_SALES_AMOUNT',
          sorter: true
        },
        {
          title: '配件成本单价',
          dataIndex: 'PART_COST_PRICE',
          sorter: true
        },
        {
          title: '配件成本金额',
          dataIndex: 'PART_COST_AMOUNT',
          sorter: true
        },
        {
          title: '毛利(不含税)',
          dataIndex: 'SALES_PART_INTERESTS',
          sorter: true,
          render: props => {
            return <span>{(props.row.PART_SALES_AMOUNT/1.13).toFixed(2) -props.row.PART_COST_AMOUNT}</span>;
          }
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true
        },
        {
          title: '九大类',
          dataIndex: 'PART_MAIN_TYPE',
          sorter: true
        },
        {
          title: '发料人',
          dataIndex: 'SENDER',
          sorter: true
        },
        {
          title: '入账日期',
          dataIndex: 'FINISHED_DATE',
         dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '归还日期',
          dataIndex: 'DATE',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
       {
          title: '发料时间',
          dataIndex: 'SEND_TIME',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.RO_STATUS, '8049')}</span>;
          }
        },
        {
          title: '结算日期',
          dataIndex: 'BALANCE_TIME',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '结清日期',
          dataIndex: 'SQUARE_DATE',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '关单日期',
          dataIndex: 'BALANCE_CLOSE_TIME',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true
        },
        {
          title: '销售顾问',
          dataIndex: 'CONSULTANT',
          sorter: true
        }
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  },
  mounted() {
    this.BaseTable = this.$refs.partTable.$refs.pageTable;

    let list={
      STORAGE_CODE:'OEM库',
      STORAGE_POSITION_CODE:'20',
      SALES_PART_NO:'SO1801180001',
      PART_NO:'X05W20QSP2',
      PART_NAME:'机油',
      PART_MODEL_GROUP_CODE_SET:'',
      PART_SALES_PRICE:100.00,
      PART_QUANTITY:10.00,
      SALES_AMOUNT:1000.00,
      SALES_DISCOUNT:1.00,
      PART_SALES_AMOUNT:1000.00,
      PART_COST_PRICE:51.12,
      PART_COST_AMOUNT:511.23,
      CUSTOMER_NAME:'李老板',
      RO_NO:'RO1801280014',
      PART_MAIN_TYPE:'机电类',
      SENDER:'蒋小玲',
      FINISHED_DATE:'2018-01-22',
      DATE:'',
      SEND_TIME:'2018-01-22',
      RO_STATUS:80491001,
      BALANCE_TIME:'2018-03-05',
      SQUARE_DATE:'2018-01-18',
      BALANCE_CLOSE_TIME:'2018-01-18',
      REMARK:'1233',
      CONSULTANT:''
    }
    this.listResult=[list];

  }

};
</script>

<style scoped lang="less">

</style>
